// JavaScript Document

	/**
	 * alert 提示插件
	 * @param {string} alertCon 提示内容
	 * @param {string} leixing 提示样式，正确提示alert-success
	 * @description 弹出提示2秒后自动消失
	 * @example 
 	 * $.alert("错误提示","alert-danger");<br>
 	 * $.alert("正确提示","alert-success");<br>
 	 * $.alert("提示","alert-info");<br>
 	 * $.alert("警告","alert-warning");<br>
	 */
	$.alert = function(alertCon,leixing){
		
		if(arguments.length == 0){
			var alertCon = "成功提示"//var alertCon 要提示的内容
			var leixing = "alert-success"//var leixing 正确提示：alert-success,错误提示：alert-danger  提示：alert-info  警告：alert-warning；
		}else if(arguments.length == 1){
			var leixing = "alert-success"//var leixing 正确提示：alert-success,错误提示：alert-danger  提示：alert-info  警告：alert-warning；
		}
		var alert1 = $("<div/>")
		.css({"position":"fixed","left":"50%","z-index":"100000","top":"10px"})
		.hide() 
		.addClass("alert alert-dismissible "+leixing)
		.attr("role","alert")
		.html('  <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+alertCon)
		.appendTo("body");
		alert1.css({"margin-left":(-($(alert1).width()/2))})
		.fadeIn(100)
		.delay(1000).fadeOut(function(){
			$(this).remove();
		});
		
	}


//单选按钮效果
$.fn.radio = function(callbak){
	this.on("click",".btn",function(){
		$(this).addClass("btn-primary").siblings(".btn-primary").removeClass("btn-primary").addClass("btn-default");
		callbak($(this));//调用回调函数，回调函数使用当前点击对像做为参数
	});
	
	return this;
}


$(function () {
	
	
	//候选人备注 从左侧弹窗
	$.fn.beizhu = function(open){
		var me = this;
		var close = function(){//关闭备注事件函数
			me.animate({"left":-me.width()-20});
			$("body").off("click",close);
			me.find(".close").off("click",close);
		}
		//阻止展开的内容区域事件冒泡
		me.click(function(e){
			e.stopPropagation();
		});
		if(open == "close"){
			close();
		}else{
			me.animate({"left":0});  //展开备注
			if($("body")){
				$("body").on("click",close);  //展开后对文档添加关闭事件
			}
			if(me.find(".close")){
				this.find(".close").on("click",close);
			}
		}
		return this;
	}
	//表格排序
	//传入字符串为“desc” 或“asc”
	$.fn.order = function(ascOrDesc){ 
		var self = this;
		function asc(){
			//正序排序
			self.find("i.caret-top").removeClass("caret-grey");
			self.find("i.caret-down").addClass("caret-grey");
		}
		function desc() {
			//倒序排序
			self.find("i.caret-down").removeClass("caret-grey");
			self.find("i.caret-top").addClass("caret-grey");
		}
		if(ascOrDesc=="asc") asc();
		if(ascOrDesc=="desc") desc();
		return self;
	}
	
	
	
	//候选人颜色标签切换
	$.fn.biaoQian = function(callbak){
		var me = this;
		var open = "open";
		//展开后的标签
		var zhankaihou = '<div class="houxuanren-tanchu">'+
			'<ul class="list-unstyled list-inline">'+
							'<li><span class="glyphicon glyphicon-tag glyphicon-biaoqian" style="color: #ff7c7c;"></span></li>'+
							'<li><span class="glyphicon glyphicon-tag glyphicon-biaoqian" style="color: #ffbf33;"></span></li>'+
							'<li><span class="glyphicon glyphicon-tag glyphicon-biaoqian" style="color: #f6e732;"></span></li>'+
							'<li><span class="glyphicon glyphicon-tag glyphicon-biaoqian" style="color: #b5e123;"></span></li>'+
							'<li><span class="glyphicon glyphicon-tag glyphicon-biaoqian" style="color: #7fc7ff;"></span></li>'+
							'<li><span class="glyphicon glyphicon-tag glyphicon-biaoqian" style="color: #e4a5ff;"></span></li>'+
							'<li><span class="glyphicon glyphicon-tag glyphicon-biaoqian" style="color: #c8c8c8;"></span></li>'+
			'</ul>'+
			'</div>';
		
		var close = function(){//关闭备注事件函数
			zhankaicon.animate({"width":0},"fast",function(){zhankaicon.remove();});
			$("body").off("click",close);
		}
		if(open == "close"){
//			close();
		}else if(open == "open"){
			var zhankaicon = $(zhankaihou).appendTo(me.parent())
			.show().animate({"width":300},"fast");  //展开颜色切换标签
			//将选中的颜色标签付给标签
			zhankaicon.one("click","span",function(e){
//				e.stopPropagation();
				 //取得被点击的标签颜色
				var biaoqiancolor = this.style.color;
				$(this).parents(".houxuanren-tanchu").siblings("span").get(0).style.color = biaoqiancolor;
				callbak.call(me,biaoqiancolor); //回调函数给程序处理保存服务器颜色值
			});
			$("body").on("click",close);  //展开后对文档添加关闭事件
		}
		
		return this;
	}
	
});





